/* -*-c++-*- */
/* osgGIS - GIS Library for OpenSceneGraph
 * Copyright 2007-2008 Glenn Waldron and Pelican Ventures, Inc.
 * http://osggis.org
 *
 * osgGIS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

#ifndef _OSGGISPROJECTS_XML_DOM_H_
#define _OSGGISPROJECTS_XML_DOM_H_ 1

#include <osgGISProjects/Common>
#include <vector>
#include <map>
#include <string>
#include <stack>

namespace osgGISProjects
{
    class XmlNode : public osg::Referenced
    {
    public:
        XmlNode();
        
        virtual ~XmlNode() { }

        virtual bool isElement() const =0;

        virtual bool isText() const =0;
    };

    typedef std::vector<osg::ref_ptr<XmlNode> > XmlNodeList;

    typedef std::map<std::string,std::string> XmlAttributes;

    class XmlElement : public XmlNode
    {
    public:
        XmlElement( const std::string& name );
        
        XmlElement( const std::string& name, const XmlAttributes& attrs );
        
        virtual ~XmlElement() { }

        const std::string& getName() const;

        XmlAttributes& getAttrs();
        
        const XmlAttributes& getAttrs() const;

        const std::string& getAttr( const std::string& key ) const;
      
        XmlNodeList& getChildren();
        
        const XmlNodeList& getChildren() const;
        
        XmlElement* getSubElement( const std::string& name ) const;
        
        XmlNodeList getSubElements( const std::string& name ) const;
        
        std::string getText() const;
        
        std::string getSubElementText( const std::string& tag ) const;

    public: // XmlNode
        virtual bool isElement() const { return true; }

        virtual bool isText() const { return false; }

    private:
        std::string name;
        XmlAttributes attrs;
        XmlNodeList children;        
    };

    typedef std::vector<osg::ref_ptr<XmlElement> > XmlElementList;
    
    typedef std::stack<osg::ref_ptr<XmlElement> > XmlElementStack;
    
    typedef std::stack<XmlElement*> XmlElementNoRefStack;

    class XmlText : public XmlNode
    {
    public:
        XmlText( const std::string& value );
        
        virtual ~XmlText() { }

        const std::string& getValue() const;

    public: // XmlNode
        virtual bool isElement() const { return false; }

        virtual bool isText() const { return true; }
        
    private:
        std::string value;
    };    
}

#endif // _OSGGISPROJECTS_XML_DOM_H_ 1

